package linkbroker;

import java.io.File;
import ssl.*;

public class LinkBroker {

	static JavaRunCommand comm = new JavaRunCommand();
	static File tmp = new File("tmp");

	// SSL Info
	private static String clientIP = "localhost";
	private static String softwareHouseIP = "localhost";
	private static String port = "6969";

	public LinkBroker() {
		startServer();
	}

	/*
	 * Initialize the server
	 */
	private static void startServer() {
		final String[] ServerInfo = {port, tmp.getAbsolutePath(), "TLS"};
        Thread serverThread = new Thread() {
			@Override
            public void run() {
                try {
					ClassFileServer.main(ServerInfo);
				} catch (Exception e) {
					e.printStackTrace();
				}
            }
        };
		serverThread.start();
    }

	private static void getFilesFromProgrammer() {
		final String[] ClientInfo = {clientIP, port, "PROGRAM"};
        Thread programmerClientThread = new Thread() {
			@Override
            public void run() {
                try {
					Client.main(ClientInfo);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        };
		programmerClientThread.start();
    }

	private static void getFilesFromSoftwareHouse() {
		final String[] ClientInfo = {softwareHouseIP, port, "ARTIFACTS"};
        Thread softwareHouseClientThread = new Thread() {
			@Override
            public void run() {
                try {
					Client.main(ClientInfo);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        };
		softwareHouseClientThread.start();
    }

	private static void compileFinal(File[] files, File output) {
        String command = "gcc -o " + output;

        for (File file : files) {
            command += " " + file;
        }
        comm.run(command);
    }
}
